package com.woniuxy.java106crm.controller;

import com.woniuxy.java106crm.annotation.RequireMethod;
import com.woniuxy.java106crm.entity.Perms;
import com.woniuxy.java106crm.entity.Role;
import com.woniuxy.java106crm.request.ResponseResult;
import com.woniuxy.java106crm.service.RoleService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户角色表现层
 */
@Api(tags = "角色管理模块API文档")
@RestController
@RequestMapping("/role")
public class RoleController {
    @Resource
    private RoleService roleService;
    //查询全部角色
    @RequireMethod("查询全部角色")
    @GetMapping("/query")
    public ResponseResult<List<Role>> queryRoles(){
        return new ResponseResult<>(ResponseResult.OK,roleService.queryRoles());
    }
    //添加角色
    @RequireMethod("添加角色")
    @PostMapping("/addRole")
    public ResponseResult<Boolean> addRole(@RequestBody Role role){
        return new ResponseResult<>(ResponseResult.OK,roleService.addRole(role));
    }
    //给角色分配权限
    @RequireMethod("给角色分配权限")
    @PutMapping("/assignRolePerms/{id}/{permsId}")
    public ResponseResult assignRolePerms(@PathVariable("id") Integer id,@PathVariable("permsId") ArrayList<Integer> permsId){
        roleService.assignRolePerms(id,permsId);
        return  new ResponseResult<>(ResponseResult.OK,null);
    }
    //删除角色
    @RequireMethod("删除角色")
    @DeleteMapping("/deleteRole/{id}")
    public ResponseResult<Boolean> deleteRole(@PathVariable("id") Integer id){
        return  new ResponseResult<>(ResponseResult.OK,roleService.deleteRole(id));
    }
}
